
/**
 * var span = document.querySelectorAll('.icon-cover');
for (var i = 0, len = span.length; i < len; i++) {
     span[i].querySelector('span').click();
}
 */
const path = require('path')
const fs = require('fs')
var rp = require('request-promise');
var async = require('async');
let iconfontVersion =  ["2728356_j803zfa8ij",'567566_pwc3oottzol'];
let iconfontVersionName = ['阿里巴巴国际站官方图标库','avue图标'];
let iconfontUrl = `http://at.alicdn.com/t/font_$key.css`;
let taskList = []
const iconReg = /(icon-.+?):/ig
iconfontVersion.forEach((key,index)=>{
    taskList.push((callback)=>{
        rp.get({
            url: iconfontUrl.replace("$key",key)
        }).then(body=>{
            var res = body.matchAll(iconReg)
            callback(null,{
                label: iconfontVersionName[index],
                list: Array.from(res,x=>'iconfont '+x[1])
            })
        })
    })
})

async.parallel(
    taskList,
    function(err,results){
        if(!err) {
            // console.log(results)
            var iconDir = path.join(path.resolve(__dirname,'..'),'src/icon')
            console.log(iconDir)
            if(!fs.existsSync(iconDir)) {
                fs.mkdirSync(iconDir)
            }
            fs.writeFileSync(path.join(iconDir,"iconlist.js"),'export default '+JSON.stringify(results,'','\t'))
        }
    }
)